import { DialogForm } from 'custom/index'
import ExNameItem from '@/views/menus/sub-account-distribution/components/ExNameItem.vue'
import Fpdx from '../components/Fpdx.vue'
import { postZzhFpgs, postFpGsJxSjJy } from '../api'

const zzhFpGsDialog = new DialogForm('DialogForm')

const fpGsJxSjJy = async (data) => {
    let res = await postFpGsJxSjJy(data);
    console.log(res);
    if (res.length > 0) {
        data.sub_intercept = true;
        let sub_msg = '当前子账号在' + data.ksrq + '及之后在['
        for (let i = 0; i < res.length; i++) {
            sub_msg += res[i] + ","
        }
        sub_msg += ']存在服务数据，确定分配后，该时间段服务数据将会在分配客服时更新！'
        data.sub_msg = sub_msg;
    }
    return data;
}

zzhFpGsDialog
    .width('30%')
    .getApi(async (_, row) => {
        row.checkFunc = fpGsJxSjJy;
        return row;
    })
    .postApi(postZzhFpgs)
    .useGroup('分配信息')
    .useCustomItem(ExNameItem, 'companyNo').label('分部公司').required().end()
    .useItem('sqYwdx').label('税前业务底薪').setProp('disabled', true).end()
    .useItem('shYwdx').label('税后业务底薪').setProp('disabled', true).end()
    .useItem('sfmsVal').label('收费模式').setProp('disabled', true).end()
    .useCustomItem(Fpdx, 'fpgsDx').label('分配底薪').required().end()
    .useDatePicker('ksrq').label('开始日期').required().end()
    .useDatePicker('jsrq').label('结束日期').required().end()

export { zzhFpGsDialog }